<template>
    <div class="login">

        <van-cell-group inset>
            <van-field v-model="tel" name="手机号" label="手机号" placeholder="手机号" />
            <van-field v-model="password" type="password" name="密码" label="密码" placeholder="密码" />
        </van-cell-group>
        <div style="margin: 16px;">
            <van-button round block type="primary" @click="loginIn">
                提交
            </van-button>
        </div>
    </div>
</template>

<script>
import { doLogin } from '@/apis/user';
import { showToast } from 'vant';
export default {
    data() {
        return {
            tel: "",
            password: ""
        }
    },
    created() {
        this.tel = localStorage.getItem("tel")
    },
    methods: {
        loginIn() {
            doLogin({
                loginname: this.tel,
                password: this.password
            }).then(res => {
                console.log(res);
                if (res.data.code == '10010') return showToast("该用户不存在")
                if (res.data.code == '10011') return showToast("密码错误")
                // 登录成功，把token和userid存入本地
                localStorage.setItem("token", res.data.data.token)
                localStorage.setItem("userid", res.data.data.userid)
                // 跳转
                this.$router.push("/home")
            })
        }
    }
}
</script>

<style scoped></style>